package com.xuhuan.example.example063;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: huan.xu
 * @create: 2023/11/14 10:44
 * @description:
 **/
public class Example063 {

    public static void main(String[] args) {
        List<Employee> employeeList=new ArrayList<>();
        employeeList.add(new Employee(1,"A",21));
        employeeList.add(new Employee(3,"B",23));
        employeeList.add(new Employee(2,"B",22));

        System.out.println("排序前：");
        for (Employee employee : employeeList) {
            System.out.println(employee);
        }

        Collections.sort(employeeList);

//        下面是另外一种实现方式
//        Collections.sort(employeeList, new Comparator<Employee>() {
//            @Override
//            public int compare(Employee o1, Employee o2) {
//                if(o1.getId()>o2.getId()){
//                    return -1;
//                }
//                if(o1.getId()<o2.getId()){
//                    return 1;
//                }
//                return 0;
//            }
//        });
        System.out.println("排序后：");
        for (Employee employee : employeeList) {
            System.out.println(employee);
        }
    }
}
